package com.project.isaacwiki.controller;

import com.project.isaacwiki.dto.ItemComplete;
import com.project.isaacwiki.service.impl.ServiceItemOperaImpl;
import com.project.isaacwiki.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class ControllerItemOpera {

    @Autowired
    private ServiceItemOperaImpl serviceItemOpera;

    @PostMapping("/user/deleteItem")
    public Result deleteItem(Integer id) throws Exception{
        try {
            return serviceItemOpera.deleteItem(id);
        } catch (Exception e) {
            return Result.Error("删除失败");
        }
    }

    @PostMapping("/user/uploadItemImage")
    public Result uploadItemImage(MultipartFile file) throws Exception{
        return serviceItemOpera.uploadItemImage(file);
    }

    @PostMapping("/user/createItem")
    public Result createItem(@RequestBody ItemComplete itemComplete) throws Exception {
        try {
            return serviceItemOpera.createItem(itemComplete);
        } catch (Exception e) {
            return Result.Error(e.getMessage());
        }
    }

    @PostMapping("/user/updateItem")
    public Result updateItem(@RequestBody ItemComplete itemComplete) throws Exception {
        return serviceItemOpera.updateItem(itemComplete);
    }

    @PostMapping("/user/updateItemImage")
    public Result updateItemImage(MultipartFile file) throws Exception {
        return serviceItemOpera.updateItemImage(file);
    }
}
